package com.luchao.back.common.service.impl;

import com.luchao.back.common.service.UploadService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

@Service
public class UploadServiceImpl implements UploadService {

    @Override
    public boolean uploadPhoto(String path, MultipartFile image) {
        boolean flag = true;
        try {
            String fileName = image.getOriginalFilename();
            String filePath = path + fileName;

            File dest = new File(filePath);
            Files.copy(image.getInputStream(), dest.toPath());
        } catch (IOException e) {
            flag = false;
            e.printStackTrace();
        } finally {
            return flag;
        }
    }
}
